<template>
  <div>
    <ul>
      <li v-for="(item, index) in arr" :key="index">
        {{ item }} — <button @click="arr.splice(index, 1)">删除</button>
      </li>
    </ul>
    <button @click="addFn">点击生成随机数</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: [1, 3, 5, 7],
    };
  },
  methods: {
    addFn() {
      //生成随机数
      const num = Math.floor(Math.random() * 10);
      //console.log(num);
      //将随机数添加到数组中
      this.arr.push(num);
    },
  },
};
</script>

<style>
</style>